//
//  FirstViewController.m
//  Follow Me
//
//  Created by apple on 2017/3/9.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "FirstViewController.h"
#import "customCell1.h"
#import "customCell2.h"
#import "customCell3.h"
#import "customCell4.h"
#import "customCell5.h"
#import "scrollView.h"
#import "MoreViewController.h"

@interface FirstViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *themes;
@property (nonatomic, strong) NSArray *routes;
@property (nonatomic, strong) NSArray *routeDetails;
@property (nonatomic, strong) NSArray *destination;




@end

@implementation FirstViewController

- (void)viewDidLoad {
    
    
    
    //设置状态栏前景为白色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    
    [super viewDidLoad];
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath_1 = [bundle pathForResource:@"themes" ofType:@"plist"];
    NSString *plistPath_2 = [bundle pathForResource:@"routes" ofType:@"plist"];
    NSString *plistPath_3 = [bundle pathForResource:@"routeDetails" ofType:@"plist"];
    NSString *plistPath_5 = [bundle pathForResource:@"destination" ofType:@"plist"];
    self.themes = [[NSArray alloc] initWithContentsOfFile:plistPath_1];
    self.routes = [[NSArray alloc] initWithContentsOfFile:plistPath_2];
    self.routeDetails = [[NSArray alloc] initWithContentsOfFile:plistPath_3];
    self.destination = [[NSArray alloc] initWithContentsOfFile:plistPath_5];
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"customCell1" bundle:nil] forCellReuseIdentifier:@"customCell1"];
    [self.tableView registerNib:[UINib nibWithNibName:@"customCell2" bundle:nil] forCellReuseIdentifier:@"customCell2"];
    [self.tableView registerNib:[UINib nibWithNibName:@"customCell3" bundle:nil] forCellReuseIdentifier:@"customCell3"];
    [self.tableView registerNib:[UINib nibWithNibName:@"customCell4" bundle:nil] forCellReuseIdentifier:@"customCell4"];
    [self.tableView registerNib:[UINib nibWithNibName:@"customCell5" bundle:nil] forCellReuseIdentifier:@"customCell5"];

    // Do any additional setup after loading the view, typically from a nib.
   
    scrollView *cycleView = [scrollView loadCycleXib];
    cycleView.cycleArr = @[@"3.jpg",@"2.jpg",@"4.jpg",@"1.jpg"];
    [self.view addSubview:cycleView];
    
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear: animated];
    self.tabBarController.tabBar.hidden = NO;

     [self.navigationController.navigationBar setHidden:YES];
    
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear: animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)dealloc
{
    
}

#pragma mark --UITableViewDataSource协议
- (NSInteger)tableView:(UITableView *)tabelView numberOfRowsInSection:(NSInteger)section {
    return [self.themes count];
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.row>0&&indexPath.row<7){
    if (indexPath.row %2 == 1){
        static NSString *cellIdentifier = @"customCell2";
        customCell1 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell2" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        [cell configCell:self.routes[indexPath.row]];
        return cell;

    }else {
        static NSString *cellIdentifier = @"customCell3";
        customCell1 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell3" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
         [cell configCell:self.routeDetails[indexPath.row]];
        
        return cell;

    }
    }else if (indexPath.row ==8||indexPath.row ==0){
        static NSString *cellIdentifier = @"customCell1";
        customCell1 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell1" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        [cell configCell:self.themes[indexPath.row]];
        return cell;
    }else if (indexPath.row ==7||indexPath.row ==10){
        static NSString *cellIdentifier = @"customCell4";
        customCell1 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell4" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        return cell;

    }else{
        static NSString *cellIdentifier = @"customCell5";
        customCell1 *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
        if (cell == nil){
            cell=[[[NSBundle mainBundle]loadNibNamed:@"customCell5" owner:(self) options:nil]lastObject];
        }
        cell.tag = indexPath.row;
        [cell configCell:self.destination[indexPath.row]];
        return cell;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row >0&& indexPath.row<7 ){
    if (indexPath.row % 2 == 1) {
        return 160.0f;
    }else
    {
        return 44.0f;
    }
    }else if(indexPath.row ==8||indexPath.row ==0)
    {
        return 54.0f;
    }
    else if (indexPath.row ==7||indexPath.row ==10)
    {
        return 64.0f;
    }else{
        return 538.0f;
    }
}
- (IBAction)pushMoreVC:(id)sender {
    MoreViewController *moreVC = [self.storyboard instantiateViewControllerWithIdentifier:@"More"];
    choo = 0;
    [self.navigationController pushViewController:moreVC animated:YES];
    NSLog(@"线路");
}
- (IBAction)pushMoreVCAndSelectDestination:(id)sender {
    MoreViewController *moreVC = [self.storyboard instantiateViewControllerWithIdentifier:@"More"];
    choo =1;
    [self.navigationController pushViewController:moreVC animated:YES];
    NSLog(@"目的地");
}


@end
